
package com.ifcar.app.view;

import com.ifcar.app.util.ThemeSettingsHelper;
import com.ifcar.app.activity.R;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

public class PreferenceListView extends ListView {

    public PreferenceListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public PreferenceListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public PreferenceListView(Context context) {
        super(context);
    }

    @Override
    protected void layoutChildren() {
        super.layoutChildren();

        final int N = getChildCount();
        for (int i = 0; i < N; i++) {
            applyThemeForChild(getChildAt(i));
        }
    }

    private void applyThemeForChild(View child) {
        final Context context = getContext();
        final ThemeSettingsHelper themeSettingsHelper = ThemeSettingsHelper
                .getThemeSettingsHelper(context);
        TextView title = (TextView) child.findViewById(android.R.id.title);
        if (title != null) {
            themeSettingsHelper.setTextViewColor(context, title, R.color.list_title_color);
        }
        TextView summary = (TextView) child.findViewById(android.R.id.summary);
        if (summary != null) {
            themeSettingsHelper.setTextViewColor(context, summary, R.color.list_desc_color);
        }
    }
}
